package com.user.config;


import com.user.common.interceptor.UserInterceptor;
import com.user.common.tools.JwtUtils;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableAspectJAutoProxy(exposeProxy = true)
public class WebMvcConfig implements WebMvcConfigurer {
    @Resource
    private JwtUtils jwtUtils;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    //.excludePathPatterns("/**")
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInterceptor(jwtUtils, stringRedisTemplate))
                .excludePathPatterns(
                        //验证码获取
                        "/Utils/code/**",
                        "/user/login/**",
                        "/user/user_info",
                        "/admin/AdminLogin",
                        "/user/user_info/forget/password",
                        "/user/blog//listByTime/firstPage",
                        "/user/blog//detail/release/**",
                        "/user/item/listByTime/firstPage",
                        "/user/item/detail/**",
                        "/doc.html",
                        "/webjars/**",
                        "/v3/api-docs/**",
                        "/swagger-ui.html"
                ).order(0);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置拦截器访问静态资源
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/favicon.ico")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
